package com.starblink.wishlist.wishlistdetails.ui.cells

import android.annotation.SuppressLint
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.*
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.basic.style.databinding.BaseLayoutEmptyWishTemplateBinding
import com.starblink.wishlist.databinding.ItemBoardDetailsChildBinding
import com.starblink.wishlist.wishboards.ui.bean.*
import com.starblink.wishlist.wishlistdetails.ui.bean.RvBoardDetailsItemEntry


/**
 * feeds无数据
 */
class EmptyBoardDetailsCell(
    binding: BaseLayoutEmptyWishTemplateBinding,
) :
    BaseBindingVH<RvNoBoardsEntry, BaseLayoutEmptyWishTemplateBinding>(binding) {


    init {
        itemView.layoutParams = StaggeredGridLayoutManager.LayoutParams(
            StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT,
            StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT
        ).apply {
            isFullSpan = true
        }
    }

    override fun onBind(model: RvNoBoardsEntry, position: Int) {
        binding.root.post {
            binding.root.setEmptyViewForWishTemplate(
                title = "The Board is Empty",
                subTitle = "You haven't added any items yet",
                marginTop = 32.dp,
                marginBottom = 32.dp
            )
        }
    }
}


/**
 * 心愿单-收藏商品列表项视图
 * @note My Wishlist-All Items页面 和 Wishlist Detail页面复用该视图
 * @param isSelf true-我的心愿单；false-他人心愿单
 * @param wListId null表示My Wishlist-All Items页面， 非null表示Wishlist Detail页面
 */
class BoardDetailsItemsCell(
    binding: ItemBoardDetailsChildBinding,
    var spmPageValue: Int,
    var wListId: String? = null,
    var isSelf: Boolean = true,
    private val deleteClickCallback: ((
        model: RvBoardDetailsItemEntry,
    ) -> Unit)? = null,
    private val choiceClickCallback: ((
        position: Int, isChoice: Boolean,
    ) -> Unit)? = null,
) :
    BaseBindingVH<RvBoardDetailsItemEntry, ItemBoardDetailsChildBinding>(binding) {

    init {
        itemView.layoutParams = StaggeredGridLayoutManager.LayoutParams(
            StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT,
            StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT
        ).apply {
            isFullSpan = true
        }
    }

    @SuppressLint("SetTextI18n")
    override fun onBind(model: RvBoardDetailsItemEntry, position: Int) {
        binding.wtItem.setData(
            showChoiceMode = model.showCheckMode,
            hasChoice = model.hasChoice,
            isSelf = isSelf,
            wishlistId = wListId,
            product = model.wishItem,
            position = position,
            spmPageValue = spmPageValue,
            isFirstItem = model.isFirst,
            choiceClickCallback = {
                choiceClickCallback?.invoke(position, it)
            },
            deleteClickCallback = {
                if (it) {
                    deleteClickCallback?.invoke(model)
                }
            },
        )
    }
}











